package com.exit490.cfp.helper;

import android.annotation.SuppressLint;

import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class DateHelpper {

    @SuppressLint("SimpleDateFormat")
    public static Date converteStringParaDate(String data) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/mm/dd", Locale.ENGLISH);
        java.util.Date date = null;
        try {
            date = dateFormat.parse(data);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        Date dateSQL = new Date(calendar.getTimeInMillis());
        return dateSQL;
    }

    public static Date mesPosterior(Date date) {

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.MONTH, 1);
        date = c.getTime();

        return date;

    }

    public static Date mesAnterior(Date date) {

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.MONTH, -1);
        date = c.getTime();

        return date;

    }

    public static String retornaNomeDoMes(Date date) {

        DateFormat df2 = new SimpleDateFormat("MMMMM", new Locale("pt", "BR"));
        String mesPorExtenso = df2.format(date);

        return mesPorExtenso;
    }

}
